﻿using Medianamik.Core.Urls;
using NUnit.Framework;

namespace Medianamik.Tests.Unit.Medianamik.Core.Urls
{
    [TestFixture]
    public class PathSegmentFormaterTest
    {
        private IPathSegmentFormater _formater;
        [SetUp]
        public void Init()
        {
            _formater = new PathSegmentFormater();
        }
        [Test]
        public void Formater_should_trim_spaces_in_segments()
        {
            var segment = new PathSegment(" test1 ");
            var expected = "test1";
            var actual = _formater.Format(segment);
            Assert.That(actual, Is.EqualTo(expected));
        }

        [Test]
        public void Formated_segments_should_start_with_an_alphanumeric_character()
        {
            var segment = new PathSegment("~!@#$%^&*()-_test1");
            var expected = "test1";
            var actual = _formater.Format(segment);
            Assert.That(actual, Is.EqualTo(expected));
        }

        [Test]
        public void Formater_should_remove_nonalphanumeric_characters()
        {
            var segment = new PathSegment("t#e$s&t*1");
            var expected = "test1";
            var actual = _formater.Format(segment);
            Assert.That(actual, Is.EqualTo(expected));
        }
        [Test]
        public void Formater_should_replace_spaces_by_hyphens()
        {
            var segment = new PathSegment("t e s t 1");
            var expected = "t-e-s-t-1";
            var actual = _formater.Format(segment);
            Assert.That(actual, Is.EqualTo(expected));
        }
        [Test]
        public void Formated_segments_should_not_contains_consecutive_hyphens()
        {
            var segment = new PathSegment("test1      test2");
            var expected = "test1-test2";
            var actual = _formater.Format(segment);
            Assert.That(actual, Is.EqualTo(expected));
        }
    }
}